package com.doupi.partner.dal;

import com.doupi.partner.model.BusinessRelation;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.session.RowBounds;

import java.util.List;

public interface BusinessRelationMapper {
	int deleteByPrimaryKey(Long id);

	int insert(BusinessRelation record);

	BusinessRelation selectByPrimaryKey(Long id);

	int updateByPrimaryKeySelective(BusinessRelation record);

	int countBusinessRelation(BusinessRelation businessRelation);

	List<BusinessRelation> queryBusinessRelations(BusinessRelation businessRelation, RowBounds rowBounds);

	List<BusinessRelation> selectBusinessRelationForUpdate(BusinessRelation businessRelation);

	BusinessRelation selectBusinessRelationForUpdateByPrimaryKey(Long id);

	@Select("<script>select count(1) from t_business_relation  <where> "
			+ " <if test=\"partnerAdministratorId != null and partnerAdministratorId gt 0\">and partner_administrator_id = #{partnerAdministratorId,jdbcType=BIGINT}</if> "
			+ " <if test=\"partnerAdministratorId != null and partnerAdministratorId lt 0\">and partner_administrator_id != -#{partnerAdministratorId,jdbcType=BIGINT}</if> "
			+ "<trim prefix=\"and (\" suffix=\")\" prefixOverrides=\"OR\">"
			+ " <if test=\"superiorPartnerAdministratorId != null\">or superior_partner_administrator_id = #{superiorPartnerAdministratorId,jdbcType=BIGINT}</if> "
			+ " <if test=\"cityAdministratorId != null\">or city_administrator_id = #{cityAdministratorId, jdbcType=BIGINT}</if>"
			+ " <if test=\"substationAdministratorId != null\">or substation_administrator_id = #{substationAdministratorId,jdbcType=BIGINT}</if>" + " </trim>" + " </where></script>")
	int countBusinessRelationWithAnnotation(BusinessRelation partnerRelation);

	@Select("<script>select * from t_business_relation  <where> "
			+ " <if test=\"partnerAdministratorId != null and partnerAdministratorId gt 0\">and partner_administrator_id = #{partnerAdministratorId,jdbcType=BIGINT}</if> "
			+ " <if test=\"partnerAdministratorId != null and partnerAdministratorId lt 0\">and partner_administrator_id != -#{partnerAdministratorId,jdbcType=BIGINT}</if> "
			+ "<trim prefix=\"and (\" suffix=\")\" prefixOverrides=\"OR\">"
			+ " <if test=\"superiorPartnerAdministratorId != null\">or superior_partner_administrator_id = #{superiorPartnerAdministratorId,jdbcType=BIGINT}</if> "
			+ " <if test=\"cityAdministratorId != null\">or city_administrator_id = #{cityAdministratorId, jdbcType=BIGINT}</if>"
			+ " <if test=\"substationAdministratorId != null\">or substation_administrator_id = #{substationAdministratorId,jdbcType=BIGINT}</if>" + " </trim>" + " </where></script>")
	@ResultMap("com.doupi.partner.dal.BusinessRelationMapper.BaseResultMap")
	List<BusinessRelation> queryBusinessRelationsWithAnnotation(BusinessRelation partnerRelation, RowBounds rowBounds);
}
